package com.example.interviewrecorder.view

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.webkit.WebView
import android.webkit.WebViewClient
import com.example.interviewrecorder.LyyBaseActivity
import com.example.interviewrecorder.databinding.ActivityFeedbackBinding
import com.example.interviewrecorder.utils.LyyActivityCollector

/**
 * 用户反馈页面，使用的是腾讯的“兔小巢”
 * @Description
 * @Author Yingyong Lao
 * @Date 2025/5/18 22:26
 */
class FeedbackActivity : LyyBaseActivity() {
    private val binding by lazy {
        ActivityFeedbackBinding.inflate(layoutInflater)
    }
    @SuppressLint("SetJavaScriptEnabled")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        binding.webView.settings.javaScriptEnabled=true
        binding.webView.settings.domStorageEnabled=true
        val myUrl = "https://support.qq.com/product/728747"
        val webViewClient=object:WebViewClient(){
            @Deprecated("Deprecated in Java")
            override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
                super.shouldOverrideUrlLoading(view,url)
                try {
                    if (url.startsWith("weixin://")) {
                        val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
                        view.context.startActivity(intent)
                        return true
                    }
                } catch (e: Exception) {
                    return false
                }
                view.loadUrl(url)
                return true
            }
        }
        binding.webView.webViewClient=webViewClient
        binding.webView.loadUrl(myUrl)
    }

    override fun onDestroy() {
        super.onDestroy()
        binding.webView.destroy()
    }

    companion object{
        fun start(){
            val currAct= LyyActivityCollector.getCurrActivity()
            val intent= Intent(currAct,FeedbackActivity::class.java)
            currAct.startActivity(intent)
        }
    }
}